<!DOCTYPE html>
<html>
<head>
	<title>看文章</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
</head>
<body>
<h1>看文章</h1>
<div>

</div>

<!-- <div style="background:#00FF00; width: 400px"> -->
<div>
	<ul>
<?php 
	$host = 'localhost';
	$root = 'root';
	$pwd = 'root';
	$db = 'mymessageboard';
	$table = 'Messages';
	// 数据库连接
	$con = mysqli_connect($host, $root, $pwd);
	if (!$con) {
		echo "数据库连接失败<br>";
	}

	if (!mysqli_select_db($con, $db)) {
		echo "连接该数据库失败: $db <br>";
	}

	function getSome() {

		
	}
	// 取值
	//INNER join ,left join , right join
	//$sql = "Select m.title as ttt,m.id as mid ,p.name from Messages m INNER join Persons p on m.personid = p.id";
	$sql = "Select m.*,p.name, p.id as userid from Messages m INNER join Persons p on m.personid = p.id order by p.id";
	// $sql = "select * from $table order by id";
	$ret = mysqli_query($con, $sql);
	if (!$ret) {
		echo "该表为空<br>";
	} else {
		while($row = mysqli_fetch_array($ret)) {
			$personid = $row["userid"];
			$title = $row["title"];
			$msgid = $row["id"];
			$content = $row["content"];
			$createtime = $row["createtime"];
			$personname = $row["name"];

			// $str = "<td>";
			$str = "<li><a href='messagedetail.php?id=". $msgid ."'>" . "文章id = " . $msgid . ", 输出标题 = " . $row["title"] . ", 内容 = " . $content .", 名字 = " . $personname . ", 用户id = " . $personid . "<br>" .  "</li></a>";
			// $str . = "</td";

			echo $str;

			//echo "文章id = " . $msgid . ", 输出标题 = " . $row["title"] . ", 内容 = " . $content .", 名字 = " . $personname . ", 用户id = " . $personid . "<br>";
			// print_r($row);
			// echo "<br><br><br>";
		}

	}
?>	
</ul>
</div>


</body>
</html>